<template>
  <div class="home">
    <header class="page-header">
      <div class="header-content">
        <div class="logo">芹音妙盒</div>
        <div class="search-bar" @click="Search">
          <input type="text" placeholder="搜索商品" />
          <i class="search-icon">🔍</i>
        </div>
      </div>
    </header>
    
    <main class="content">
      <!-- 轮播图区域 -->
      <section class="banner-section">
        <swiper
          :modules="[Autoplay, Pagination, Navigation]"
          :slides-per-view="1"
          :loop="true"
          :autoplay="{
            delay: 3000,
            disableOnInteraction: false
          }"
          :pagination="{
            clickable: true
          }"
          :navigation="true"
          class="banner-swiper"
        >
          <swiper-slide v-for="(image, index) in bannerImages" :key="index">
            <div class="banner-image">
              <img :src="image.url" :alt="image.title">
              <div class="banner-title">{{ image.title }}</div>
            </div>
          </swiper-slide>
        </swiper>
      </section>

      <!-- 商品分类导航 -->
      <section class="category-section">
        <div class="category-items">
          <div class="category-item" v-for="(item, index) in categories" :key="index" @click="goToOrder">
            <div class="category-icon">{{ item.icon }}</div>
            <span>{{ item.name }}</span>
          </div>
        </div>
      </section>

      <!-- 特色商品推荐 -->
      <section class="featured-section">
        <h2>人气推荐</h2>
        <div class="featured-items">
          <div class="featured-item" v-for="item in featuredItems" :key="item.id" @click="router.push('/order')">
            <div class="item-image">
              <img :src="item.image" :alt="item.title">
            </div>
            <div class="item-info">
              <h3>{{ item.title }}</h3>
              <p class="description">{{ item.description }}</p>
              <p class="price">¥{{ item.price }}</p>
            </div>
          </div>
        </div>
      </section>

      <!-- 会员专区 -->
      <section class="member-section">
        <div class="member-header">
          <h2>会员专享</h2>
          <span class="view-all" @click="more">查看更多 ></span>
        </div>
        <div class="member-content">
          <div class="member-card">
            <h3>会员特权</h3>
            <p>尊享会员折扣</p>
            <button class="member-btn">立即开通</button>
          </div>
          <div class="member-benefits">
            <div class="benefit-item" v-for="i in 3" :key="i">
              <div class="benefit-icon">🎁</div>
              <span>会员特权 {{ i }}</span>
            </div>
          </div>
        </div>
      </section>
    </main>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Autoplay, Pagination, Navigation } from 'swiper/modules'
// 导入 Swiper 必需的样式文件
import 'swiper/css'
import 'swiper/css/pagination'
import 'swiper/css/navigation'

const router = useRouter()
const bannerImages = [
  { url: '/src/assets/hd.jpg', title: '精选活动1' },
  { url: '/src/assets/hd.jpg', title: '精选活动2' },
  { url: '/src/assets/hd.jpg', title: '精选活动3' }
]

const categories = [
  { icon: '☕', name: '咖啡' },
  { icon: '🍰', name: '甜点' },
  { icon: '🥪', name: '轻食' },
  { icon: '🍹', name: '饮品' },
  { icon: '🎁', name: '礼品' }
]

const goToOrder = () => {
  router.push('/order')
}

const more = () => {
  router.push('/Myother/member')
}
//搜索页面search
const Search = () => {
  router.push('/Search/Search')
}

const featuredItems = [
  { id: 1, title: '精品咖啡', description: '香醇浓郁，回味无穷', price: 29.9, image: '/src/assets/kf.jpg' },
  { id: 2, title: '精品咖啡', description: '香醇浓郁，回味无穷', price: 39.9, image: '/src/assets/kf.jpg' },
  { id: 3, title: '精品咖啡', description: '香醇浓郁，回味无穷', price: 49.9, image: '/src/assets/kf.jpg' },
  { id: 4, title: '精品咖啡', description: '香醇浓郁，回味无穷', price: 59.9, image: '/src/assets/kf.jpg' }
]
</script>

<style scoped>
.home {
  padding-bottom: 76px;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.page-header {
  padding: 15px 20px;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #42b883;
}

.search-bar {
  flex: 1;
  display: flex;
  align-items: center;
  background: #f5f5f5;
  border-radius: 20px;
  padding: 8px 15px;
}

.search-bar input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
}

.search-icon {
  margin-left: 8px;
  color: #999;
}

.content {
  padding: 15px 20px;
}

.banner-section {
  margin-bottom: 20px;
}

.banner-swiper {
  width: 100%;
  height: 200px;
  border-radius: 12px;
  overflow: hidden;
}

.banner-image {
  position: relative;
  width: 100%;
  height: 100%;
}

.banner-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.banner-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  color: white;
  font-size: 18px;
}

:deep(.swiper-pagination-bullet) {
  background: white;
  opacity: 0.8;
}

:deep(.swiper-pagination-bullet-active) {
  background: #42b883;
}

:deep(.swiper-button-prev),
:deep(.swiper-button-next) {
  color: white;
  background: rgba(0,0,0,0.3);
  width: 35px;
  height: 35px;
  border-radius: 50%;
}

:deep(.swiper-button-prev:after),
:deep(.swiper-button-next:after) {
  font-size: 16px;
}

.category-section {
  margin-bottom: 20px;
}

.category-items {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 15px;
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.category-icon {
  font-size: 24px;
  background: #f5f5f5;
  width: 50px;
  height: 50px;
  border-radius: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-item span {
  font-size: 12px;
  color: #666;
}

.featured-section {
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.featured-section h2 {
  font-size: 18px;
  color: #333;
  margin: 0 0 15px 0;
}

.featured-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
}

.featured-item {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.2s;
}

.featured-item:active {
  transform: scale(0.98);
}

.item-image.placeholder {
  background: #f5f5f5;
  height: 120px;
  width: 100%;
}

.item-image {
  height: 120px;
  width: 100%;
  overflow: hidden;
  background: #f5f5f5;
}

.item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.featured-item:hover .item-image img {
  transform: scale(1.05);
}

.item-info {
  padding: 10px;
}

.item-info h3 {
  margin: 0;
  font-size: 14px;
  color: #333;
}

.description {
  font-size: 12px;
  color: #999;
  margin: 5px 0;
}

.price {
  color: #f56c6c;
  font-size: 16px;
  font-weight: bold;
  margin: 5px 0 0 0;
}

.member-section {
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.member-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.member-header h2 {
  font-size: 18px;
  color: #333;
  margin: 0;
}

.view-all {
  color: #999;
  font-size: 14px;
}

.member-content {
  display: flex;
  gap: 15px;
}

.member-card {
  flex: 1;
  background: linear-gradient(135deg, #42b883, #35495e);
  border-radius: 12px;
  padding: 15px;
  color: white;
}

.member-card h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
}

.member-card p {
  margin: 0 0 15px 0;
  font-size: 14px;
  opacity: 0.8;
}

.member-btn {
  background: white;
  color: #42b883;
  border: none;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}

.member-benefits {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.benefit-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.benefit-icon {
  font-size: 24px;
}

.benefit-item span {
  font-size: 12px;
  color: #666;
  text-align: center;
}
</style>